package org.gwt.grin.client.features;

import java.util.Set;

import org.gwt.grin.client.Feature;
import org.gwt.grin.client.util.Graphics;

/**
 * Abstract base class for features that modify a single child feature.
 * 
 * @author Bill Foote (http://jovial.com)
 * @author ggeorg
 */
public abstract class Modifier extends Feature {

	protected Feature part;
	protected boolean activated = false;

	@Deprecated
	public Modifier(String name, Feature part) {
		super(name);
		this.part = part;
	}

	public Feature getPart() {
		return part;
	}

	public void addSubgraph(Set<Feature> set) {
		if (set.contains(this)) {
			return;
		}
		super.addSubgraph(set);
		part.addSubgraph(set);
	}

	@Override
	public int getX() {
		return part.getX();
	}

	@Override
	public int getY() {
		return part.getY();
	}

	@Override
	public void initialize() {
		// The show will initialize our sub-feature, so we don't need to do
		// anything here.
	}

	@Override
	public void destroy() {
		// The show will destroy our sub-feature, so we don't need to do
		// anything here.
	}

	@Override
	protected void setActivateMode(boolean mode) {
		activated = mode;
		if (mode) {
			part.activate();
			setChildChanged();
		} else {
			part.deactivate();
			setChildChanged();
		}
	}

	protected void setChildChanged() {
		part.markAsChanged();
	}

	@Override
	protected int setSetupMode(boolean mode) {
		if (mode) {
			return part.setup();
		} else {
			part.unsetup();
			return 0;
		}
	}

	@Override
	public boolean needsMoreSetup() {
		if (part.needsMoreSetup()) {
			return true;
		}
		return false;
	}

	@Override
	public void markAsChanged() {
		part.markAsChanged();
	}

	@Override
	public void paintFrame(Graphics gc) {
		part.paintFrame(gc);
	}

	@Override
	public void paintDone() {
		part.paintDone();
	}

	@Override
	public void nextFrame() {
		part.nextFrame();
	}
}
